package com.pay.game.central.web.service;

import com.github.pagehelper.Page;
import com.pay.game.central.utils.DateTimeUtil;
import com.pay.game.central.web.bean.Order;
import com.pay.game.central.web.mapper.OrderMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

@Service
public class OrderService {


    @Autowired
    private OrderMapper orderMapper;

    public Order findPddOrderById(String id){
        return orderMapper.findOrderById(id);
    }

    public void insertPddOrder(Order order){
        orderMapper.insertItem(order);
    }

    public void updateSignTime(Order order){ orderMapper.updateSignTime(order); }

    public Page<Order> list(boolean isAdmin, String rootUserId, String id, int price,String startTime, String endTime,String storeId, String storeName) {
        String userId = isAdmin? null : rootUserId;
        long start = DateTimeUtil.parseDate(startTime,DateTimeUtil.TIME_PATTERN).getTime() / 1000;
        long end = DateTimeUtil.parseDate(endTime,DateTimeUtil.TIME_PATTERN).getTime() / 1000;
        return orderMapper.list(id,userId, price, start, end, storeId, storeName);
    }

    /**
     *
     * @param needSign 是否可签收( 0不可签收 1可签收 )
     */
    public  Page<Map<String, Object>> listSignHistory(boolean isAdmin, String rootUserId, int needSign){
        String userId = isAdmin? null : rootUserId;
        return orderMapper.listSignHistory(userId, needSign);
    }


    /**
     * 获取需要签收的数据
     */
    public  Page<Map<String, Object>> listNeedSign(boolean isAdmin, String rootUserId, String storeId, String storeName){
        String userId = isAdmin? null : rootUserId;
        return orderMapper.listNeedSign(userId, storeId, storeName);
    }

}
